#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using tl = tuple < int, int, int >;
using vec = vector < int >;
using veg = vector < pair < int, ll > >;

ll read() {
    ll x = 0; bool f = 0; char ch = getchar(); while(!isdigit(ch)) f |= ch == '-',ch = getchar();
    while(isdigit(ch)) x = x * 10 + (ch ^ 48),ch = getchar(); return f ? -x : x;
}

const int N = 1e5 + 10;
const ll inf = 1e18;

veg G[N];
ll dis[N], to[N], w, diam;
int n, m, fa[N], pot[N << 1], dfn[N], R[N], tim;

namespace seg {
	struct node { ll mn, mx, mx1, mx2, res; } val[N << 2];
	node operator + (const node &a, const node &b) {
		node c;
		c.mn = min(a.mn, b.mn); c.mx = max(a.mx, b.mx);
		c.mx1 = max(a.mx1, b.mx1); c.mx2 = max(a.mx2, b.mx2);
		c.res = max(a.res, b.res);
		c.mx1 = max(c.mx1, a.mx - 2 * b.mn); c.mx2 = max(c.mx2, b.mx - 2 * a.mn);
		c.res = max(c.res, a.mx1 + b.mx); c.res = max(c.res, a.mx + b.mx2);
		return c;
	}
	int ch[N << 2][2], L[N << 2], R[N << 2], ndn, md[N << 2], rt;
	ll tg[N << 2];
	void pt(int o, ll v) { tg[o] += v; val[o].mn += v; val[o].mx += v; val[o].mx1 -= v; val[o].mx2 -= v; } // res no need.
	void pd(int o) { if(tg[o]) pt(ch[o][0], tg[o]), pt(ch[o][1], tg[o]), tg[o] = 0; }
	void build(int &o, int l, int r) {
		o = ++ndn; L[o] = l; R[o] = r; tg[o] = 0; if(l == r) return val[o].mn = val[o].mx = dis[pot[l]], val[o].mx1 = val[o].mx2 = val[o].res = -inf, void();
		md[o] = (L[o] + R[o]) >> 1;
		build(ch[o][0], L[o], md[o]); build(ch[o][1], md[o] + 1, R[o]);
		val[o] = val[ch[o][0]] + val[ch[o][1]];
	}
	int xl, xr; ll v;
	void upd(const int &o) {
		if(xl <= L[o] && R[o] <= xr) return pt(o, v); pd(o);
		if(xl <= md[o]) upd(ch[o][0]);
		if(xr > md[o]) upd(ch[o][1]);
		val[o] = val[ch[o][0]] + val[ch[o][1]];
	}
	void upd(const int &l, const int &r, const ll &v) { xl = l; xr = r; seg :: v = v; upd(rt); }
	ll get() { return max(val[rt].res, val[rt].mx); }
}

int dep[N];

void dfs1(int x, int p) {
	fa[x] = p; pot[dfn[x] = R[x] = ++tim] = x; dep[x] = dep[p] + 1;
	for(auto v : G[x]) if(v.fi ^ p) dis[v.fi] = dis[x] + v.se, to[v.fi] = v.se, dfs1(v.fi, x), pot[R[x] = ++tim] = x;
}

ll ans = 0;
int u[N], v[N];
ll z[N];

int main() {
#ifndef ONLINE_JUDGE
    freopen("1.in","r",stdin);
#endif
	n = in, m = in, w = in;
	rep(i, 1, n - 1) u[i] = in, v[i] = in, z[i] = in, G[u[i]].pb({ v[i], z[i] }), G[v[i]].pb({ u[i], z[i] }); 
	dis[1] = 0; dfs1(1, 0);
	seg :: build(seg :: rt, 1, tim);
	while(m--) {
		ll x = in, tx = in;
		x = (x + ans) % (n - 1) + 1, tx = (tx + ans) % w;
		x = dep[u[x]] > dep[v[x]] ? u[x] : v[x];
		seg :: upd(dfn[x], R[x], tx - to[x]);
		to[x] = tx;
		printf("%lld\n", ans = seg :: get());
	}
	return 0;
}
